﻿using System;
using System.Collections.Generic;
using HAVNet.Core.Lambda;


namespace HAVNet.Intros.ParseTree
{
    public class NodeNonTerminalSymbol : NodeSymbol
    {
        public readonly string  val         = "";
        List<NodeSymbol>        _children   = new List<NodeSymbol>();
        
        public NodeNonTerminalSymbol (NodeSymbol parent, string val)
            : base (parent)
        {
            this.val = val;
        }

        public override void add (NodeSymbol treeNode)
        {
            _children.Add ( treeNode );
        }

        public override void remove (NodeSymbol treeNode)
        {
            _children.Remove (treeNode);
        }

        public override bool visit (SymbolNodeVisitFunction f, int depth)
        {
            if (! f (this, depth))
                return false;

            foreach (NodeSymbol nsx in _children)
                if (! nsx.visit (f, depth + 1))
                    return false;

            return true;
        }

        public override string ToString ()
        {
            return val;
        }
    }
}
